import os
import allure
import pytest

from config.config import BASE_DIR
from util.assert_util import assert_csv_to_db_with_details_with_allure, assert_equal_with_allure
from util.wait_util import wait_for_calculation_processing


@allure.feature("Calculation")
@allure.story("Smoke Test")
class TestcaseCalculation:

    def testcase_ppa_daily_calculation(self, setup_wf_calculation_happy_case):
        # test step
        resp = setup_wf_calculation_happy_case.trigger_ppa_daily_calculation(business_date="2025-01-01")
        wf_id = resp.get("files")[0].get("fileId")

        # wait for file processing
        process_id, calculation_status = wait_for_calculation_processing(wf_id, 'Daily_TWR')
        assert_equal_with_allure("Calculation Daily_TWR status", calculation_status, "Success")
        db_table_name = "PPA.TB_PPA_RESULT_DAILY_TWR"
        csv_file_path = os.path.join(BASE_DIR, "data", "calculation", "happy_case", "low_case","expect_result", "daily_twr.csv")
        assert_csv_to_db_with_details_with_allure(csv_file_path, db_table_name, process_id, "Calculation")

        process_id, calculation_status = wait_for_calculation_processing(wf_id, 'Daily_TWR_Aggregate')
        assert_equal_with_allure("Calculation Daily_TWR_Aggregate status", calculation_status, "Success")
        db_table_name = "PPA.TB_PPA_RESULT_DAILY_TWR_AGGREGATE"
        csv_file_path = os.path.join(BASE_DIR, "data", "calculation", "happy_case", "low_case","expect_result", "daily_twr_aggregate.csv")

        assert_csv_to_db_with_details_with_allure(csv_file_path, db_table_name, process_id, "Calculation")
